<?php
error_reporting(E_ALL);

function getDataFromExcel($file, $sheet, $rows, $cols)
{
	echo "A<br/>";
    // COM CREATE
    $excel = new COM("Excel.Application") or die ("ERROR: Unable to instantaniate COM!\r\n");
 	echo "b<br/>";
    //$excel->Visible = true; // so that we see the window on screen
	echo "c<br/>";
 
    // DATA RETRIEVAL
    $Workbook = $excel->Workbooks->Open($file) or die("ERROR: Unable to open " . $file . "!\r\n");
 	echo "d<br/>";
    $Worksheet = $Workbook->Worksheets($sheet);
 	echo "e<br/>";
    $Worksheet->Activate;
 	echo "f<br/>";
    $i = 0;
    foreach ($rows as $row)
    {
        $i++; $j = 0;
        foreach ($cols as $col)
        {
            $j++;
            $cell = $Worksheet->Range($col . $row);
            $cell->activate();
            $matrix[$i][$j] = $cell->value;
        }
    }

    // COM DESTROY
    $Workbook->Close();
    unset($Worksheet);
    unset($Workbook);
    $excel->Workbooks->Close();
    $excel->Quit();
    unset($excel);

    return $matrix;
}

// define inputs
echo 'hpla';
$xls_path = "c:\\backup\\myfile.xls"; // input file
echo $xls_path;
$xls_sheet = 1; // sheet #1 from file
$xls_rows = range(3, 20, 1); // I want extract rows 3 - 20 from test.xls with 1 row stepping
$xls_cols = array("B", "D", "E", "G"); // I want to extract columns B, D, E and G from the file


// retrieve data from excel
$data = getDataFromExcel($xls_path, $xls_sheet, $xls_rows, $xls_cols);

?>
<html>
<pre>
<?php print_r ($data);?>
</pre> 
</html>
